<?php
declare (strict_types = 1);
namespace app\admin\controller;
use app\admin\model\Upload;
use app\tool\controller\SendController;
use app\tool\controller\TreeController;
use think\facade\Db;
use think\facade\View;
use think\Request;

class IndexController {
	public function getCodeTool() {
		$list = SendController::getDataDetail();

		foreach ($list['data']['products'] as $key => $value) {
			$name = '';
			$name = $value['meta_info']['name'];
			$description = $value['meta_info']['description'];
			Db::name('coze')->insert(['name' => $name, 'description' => $description]);

			foreach ($value['plugin_extra']['tools'] as $k => $v) {
				$name = $value['meta_info']['name'] . '__' . $v['name'];
				$description = $v['description'];
				Db::name('coze')->insert(['name' => $name, 'description' => $description]);
			}

		}
		// var_dump($list);
	}
	/*这个是一个推拽上传的东西*/
	public function Viewupload() {
		return View::fetch('Viewupload');

	}
	/**
	 * 显示资源列表
	 *
	 * @return \think\Response
	 */
	public function index() {
		View::assign([
			'name' => 'ThinkPHP',
			'email' => 'thinkphp@qq.com',
		]);
		// 模板输出
		return View::fetch('index');
	}
	public function dataPanel() {
		return View::fetch('dataPanel');
	}
	public function imgListPage($id = 0) {
		if ($id > 0) {

			$zm = Db::connect('zmDy')->name('xm')->select()->order('id desc')->toArray();
			$imgList = [];
			foreach ($zm as $k => $v) {
				$imgList[$k]['id'] = $v['ID'];
				$imgList[$k]['title'] = $v['TITLE'];
				$imgList[$k]['fileOne'] = $v['TOPIC_URL'];
				$imgList[$k]['fileTwo'] = $v['ANSWER_URL'];
			}

		} else {
			$imgList = Upload::order('id desc')->select()->toArray();
		}

		View::assign([
			'imgList' => $imgList,
		]);

		return View::fetch('imgListPage');
	}

	/**
	 * 显示创建资源表单页.
	 *
	 * @return \think\Response
	 */
	public function create() {
		//
	}
	/**
	 * 保存新建的资源
	 *
	 * @param \think\Request $request
	 * @return \think\Response
	 */
	public function save(Request $request) {
	}
	/**
	 * 显示指定的资源
	 *
	 * @param int $id
	 * @return \think\Response
	 */
	public function read($id) {
		//
	}
	/**
	 * 显示编辑资源表单页.
	 *
	 * @param int $id
	 * @return \think\Response
	 */
	public function edit($id) {
		//
	}
	/**
	 * 保存更新的资源
	 *
	 * @param \think\Request $request
	 * @param int $id
	 * @return \think\Response
	 */
	public function update(Request $request, $id) {
		//
	}
	/**
	 * 删除指定资源
	 *
	 * @param int $id
	 * @return \think\Response
	 */
	public function delete($id) {
		//
	}
	public function tree() {
		$data = [
			['id' => 1, 'name' => '你好1', 'type' => 1, 'parent_id' => 0],
			['id' => 2, 'name' => '你好2', 'type' => 1, 'parent_id' => 1],
			['id' => 3, 'name' => '你好3', 'type' => 1, 'parent_id' => 1],
			['id' => 4, 'name' => '你好4', 'type' => 1, 'parent_id' => 1],
			['id' => 5, 'name' => '你好5', 'type' => 1, 'parent_id' => 0],
			['id' => 6, 'name' => '你好6', 'type' => 1, 'parent_id' => 5],
			['id' => 7, 'name' => '你好7', 'type' => 1, 'parent_id' => 5],
			['id' => 8, 'name' => '你好8', 'type' => 1, 'parent_id' => 5],
			['id' => 9, 'name' => '你好9', 'type' => 1, 'parent_id' => 2],
			['id' => 10, 'name' => '你好10', 'type' => 1, 'parent_id' => 2],
			['id' => 11, 'name' => '你好11', 'type' => 1, 'parent_id' => 2],
			['id' => 12, 'name' => '你好12', 'type' => 1, 'parent_id' => 6],
			['id' => 13, 'name' => '你好13', 'type' => 1, 'parent_id' => 6],
			['id' => 14, 'name' => '你好14', 'type' => 1, 'parent_id' => 6],
		];
		$data = TreeController::tree($data);
		var_dump($data);
	}
}
